package com.orange.test.base;

import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextHierarchy;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

/**
 * JUnitActionBase
 */
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration(value = "src/main/webapp")
@ContextHierarchy({
  @ContextConfiguration(name = "parent", locations = "classpath:xiaoxin-config/*.xml"),
  @ContextConfiguration(name = "child", locations = "file:src/main/webapp/WEB-INF/spring-mvc.xml")
})
public class JUnitActionBase {
  @Autowired
  private WebApplicationContext webApplicationContext;
  private MockMvc mockMvc = null;

  /**
   * getMockMvc
   *
   * @return MockMvc
   */
  public MockMvc getMockMvc() {
    if (mockMvc == null) {
      mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
    }
    return mockMvc;
  }
}
